import React  from "react";
import WrapFormItem from "components/wrap-form-item";
import { Row, Col, Select, Input } from "antd";
import { messages } from "share/common";
const { Option } = Select;

const hasValue = value => value && value.entityType;

const options = [
  { label: messages('finance-2.key46')/*报销单*/, value: '1002' },
  { label: messages('finance-2.key47')/*还款单*/, value: '1008' },
  { label: messages('finance-2.key48')/*借款单*/, value: '3001' },
  { label: messages('finance-2.key49')/*付款申请单*/, value: '7001' }
];

export default {
  id: 'partner', label: messages('finance-2.key50')/*单据信息*/,
  component: <WrapFormItem>
    {(onChange, value) => (
      <Row gutter={10}>
        <Col span={8}>
          <Select
            onChange={innerValue => onChange({ entityType: innerValue, businessCode: undefined })}
            value={value.entityType}
            style={{ width: '100%' }}
            placeholder={messages('finance-2.key51')/*请选择temp*/}
          >
            {options.map(item => <Option key={item.value}>{item.label}</Option>)}
          </Select>
        </Col>
        <Col span={16}>
          <Input
            value={value.businessCode}
            disabled={!value.entityType}
            placeholder={messages('finance-2.key52')/*请输入temp2*/}
            onChange={e => onChange({ businessCode: e.target.value })}
          />
        </Col>
      </Row>
    )}
  </WrapFormItem>,
  hasValue,
  parser: value => hasValue(value) ? value : null,
  tagParser: value => value.entityType && `${options.find(item => item.value === value.entityType).label}${value.businessCode ? `:${value.businessCode}` : ''}`
}
